//
//  EPMMineViewController.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/4/26.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMMineViewController.h"
#import "EPMLoginViewController.h"
#import "EPMMineTitleCell.h"
#import "EPMMineOrderTitleCell.h"
#import "EPMMineOrderCell.h"
#import "EPMMembershipCell.h"
#import "EPMNormalCell.h"
#import "EPMMineNormalModel.h"

@interface EPMMineViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak,nonatomic) UITableView* tableView;

@property (strong,nonatomic) NSArray* normalList;
@end

@implementation EPMMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    if (!_LoginMgr.isLogin){
//        [self.navigationController pushViewController:[EPMLoginViewController new] animated:YES];
//        return;
//    }
    [self setupUI];
     [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)setupUI{
    self.navigationController.navigationBar.hidden = YES;
    
    UITableView* tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView = tableView;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(-64, 0, 0, 0));
    }];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.estimatedRowHeight = 300;
    tableView.sectionHeaderHeight = 0;
    tableView.sectionFooterHeight = 10;
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [tableView registerNib:[UINib nibWithNibName:@"EPMMineTitleCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"title"];
    [tableView registerNib:[UINib nibWithNibName:@"EPMMineOrderTitleCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"orderTitle"];
    [tableView registerNib:[UINib nibWithNibName:@"EPMMineOrderCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"order"];
    [tableView registerClass:[EPMMembershipCell class] forCellReuseIdentifier:@"member"];
    [tableView registerNib:[UINib nibWithNibName:@"EPMNormalCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"normal"];
}

#pragma mark - 数据源方法 -

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0){
        return 1;
    }else if ( section ==1){
        return 2;
    }else if (section == 2){
        return 1;
    }else{
        return self.normalList.count;
    }
    
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 0){
        EPMMineTitleCell* cell = [tableView dequeueReusableCellWithIdentifier:@"title" forIndexPath:indexPath];
        
        return cell;
    }else if (indexPath.section == 1 && indexPath.row == 0){
        EPMMineOrderTitleCell* cell = [tableView dequeueReusableCellWithIdentifier:@"orderTitle" forIndexPath:indexPath];
        
        return cell;

    }else if (indexPath.section == 1 && indexPath.row ==1){
        EPMMineOrderCell* cell = [tableView dequeueReusableCellWithIdentifier:@"order" forIndexPath:indexPath];
        return cell;
    }else if (indexPath.section == 2){
        EPMMembershipCell* cell = [tableView dequeueReusableCellWithIdentifier:@"member" forIndexPath:indexPath];
        return cell;
    }else if (indexPath.section == 3){
        EPMNormalCell*cell = [tableView dequeueReusableCellWithIdentifier:@"normal" forIndexPath:indexPath];
        cell.model = self.normalList[indexPath.row];
        return cell;
    }
    
    
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    
    return cell;
    
}


#pragma mark - 数据加载 -

- (NSArray*)normalList{
    if (_normalList == nil){
        NSString* path = [[NSBundle mainBundle]pathForResource:@"MineCell.plist" ofType:nil];
        NSArray* dictArray = [NSArray arrayWithContentsOfFile:path];
        _normalList = [NSArray yy_modelArrayWithClass:[EPMMineNormalModel class] json:dictArray];
    }
    return  _normalList;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
